#include<math.h>

enum coordinate_type {RECTANGULAR, POLAR};

struct complex_struct
{
  enum coordinate_type t;
  double a, b;
};

struct complex_struct make_from_real_img(double x, double y)
{
	struct complex_struct z;
	z.t = RECTANGULAR;
	z.a = x;
	z.b = y;
	return z;
}

struct complex_struct make_from_mag_ang(double r, double A)
{
	struct complex_struct z;
	z.t = POLAR;
	z.a = r;
	z.b = A;
	return z;
}

double real_part(struct complex_struct c)
{
  if (c.t == RECTANGULAR)
  {
    return c.a;
  }
  else
    return c.a * cos(c.b);
}

double img_part(struct complex_struct c)
{
  if (c.t == RECTANGULAR)
  {
    return c.b;
  }
  else
    return c.a * sin(c.b);
}

double magnitude(struct complex_struct c)
{
  if (c.t == RECTANGULAR)
    return sqrt(c.a * c.a + c.b * c.b);
  else
    return c.a;
}

double angle(struct complex_struct c)
{
  if (c.t == RECTANGULAR)
    return atan2(c.b, c.a);
  else
    return c.b;
}

